home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / eflibpt4.zip / DEMO / MATH / MATHNEWT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-07-21  |  1KB  |  40 lines

  1. { Borland Pascal Extended Function Library - EFLIB (C) Johan Larsson, 1996
  2.   Demonstration; Newton-Raphsons method for iterative equation solving
  3.  
  4.   EFLIB IS PROTECTED BY THE COPYRIGHT LAW AND MAY NOT BE COPIED, SOLD OR
  5.   MANIPULATED. FOR MORE INFORMATION, SEE PROGRAM MANUAL! THIS DEMONSTRAT-
  6.   ION PROGRAM MAY FREELY BE USED AND DISTRIBUTED.                          }
  7.  
  8.  
  9. uses EFLIBMTH;
  10.  
  11.  
  12. const Iterations = 1000; { Number of iterations -
  13.                            larger value gives better precision in results }
  14.  
  15. { Returns y(x) there y is the function that should be solved; y(x) = 0; x = ? }
  16. function FunctionProc (X : real) : real; far;
  17. begin
  18.      FunctionProc := PowerNumber (X, 3) + X - 3;
  19. end;
  20.  
  21. { Returns y'(x) there y is the function that should be solved }
  22. function DerivateProc (X : real) : real; far;
  23. begin
  24.      DerivateProc := 3 * PowerNumber (X, 2) + 1;
  25. end;
  26.  
  27.  
  28. var Result : real;
  29.  
  30. begin
  31.      { Newton-Raphsons method with algebratic derivate specified in function }
  32.      NewtonRaphsonsMethod (1, Iterations, Result, @FunctionProc, @DerivateProc);
  33.      WriteLn ('Newton-Raphsons method (algebrathic derivate)':45,' : ', Result:10:10);
  34.  
  35.      { Newton-Raphsons method with approximated derivate }
  36.      NewtonRaphsonsMethodDA (1, Iterations, 0.001, Result, @FunctionProc);
  37.      WriteLn ('(approximated derivate)':45,' : ', Result:10:10);
  38.  
  39.      WriteLn;
  40. end.